#include <stdio.h>
#include <stdlib.h>

#define RIEN RIEN
#define BATEAU BATEAU
#define DEJA_JOUE DEJA_JOUE
#define BATEAU_COULE BATEAU_COULE


int hasard()
{
	double n;
	n = (double) rand();
	n = n*10;
	n = n/(1<<15);
	return (int) n%10 ;
}



main()
{
/*
int i=hasard();
printf("%d\n",i);
*/


	char mer[10][10];
	char car;
	int nbateaux;
	int i,j;
	int ncoups;


	for (i=0;i<10;i++)
    		for (j=0;j<10;j++) mer[i][j] = RIEN;

	nbateaux = 10;
  	while (nbateaux > 0)
  	{
    		i = hasard();
    		j = hasard();
    		if (mer[i][j]== RIEN)
    		    {
			mer[i][j]=BATEAU;
       		     	nbateaux -=1; 
		    }
 	 }	

	nbateaux = 10 ;

//boucle princip

	ncoups = 0 ;
	while (nbateaux > 0)
  	{
    		printf(" 0 1 2 3 4 5 6 7 8 9\n");
    		for (i=0;i<10;i++)
      		{
			printf("%d ",i);
          		for (j=0;j<10;j++)
              		{
				if (mer[i][j]==BATEAU) car=RIEN;
              			else car = mer[i][j];
              			printf("%c ",car);
			}
			printf("%d\n",i);
		}
    	}	
	printf(" 0 1 2 3 4 5 6 7 8 9\n");

	printf("Entrez les coordonnees (linges colonne) : ");
	
	if (scanf("%d %d",&i,&j) != 2)  exit(0);

	ncoups += 1;
	switch (mer[i][j])
	{
	 case RIEN:
		   printf("dans l'eau\n");
		   mer[i][j]=DEJA_JOUE;
      		   break;
  	 case BATEAU:
      		   printf("Coule !\n");
      		   mer[i][j]=BATEAU_COULE;
      		   nbateaux -=1;
   		   break;
	case DEJA_JOUE:
	case BATEAU_COULE:
      		   printf ("case deja jouee\n");
                   break;
	}

	printf("vous aves gagne en %d coups . Bravo\n" , ncoups);
	exit(0);
}
